package me.keiwu.task.domain;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.keiwu.pub.util.support.DateJsonSerializer;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import java.util.Date;

/**
 * Created by kei on 03/11/2017.
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(indexes = {
        @Index(name = "idx_initiator", columnList = "initiator"),
        @Index(name = "idx_challenger", columnList = "challenger")
})
public class Challenge extends AbstractBaseEntity {

    @Id
    @GeneratedValue
    private Long id;

    /**
     * 挑战名称
     */
    @Column(length = 100)
    private String name;

    /**
     * 任务状态，0=初始化，1=进行中，2=结束，3=关闭，参考challengeState
     */
    @ColumnDefault(value = "0")
    @Column(nullable = false, columnDefinition = "TINYINT", length = 1)
    private Integer state = 0;

    /**
     * 发起者
     */
    private Long initiator;

    @ColumnDefault(value = "0")
    @Column(nullable = false)
    private Integer initiatorStep = 0;

    @Column(length = 100)
    private String initiatorName;

    @Column(length = 200)
    private String initiatorAvatar;


    /**
     * 挑战者
     */
    private Long challenger;

    @ColumnDefault(value = "0")
    @Column(nullable = false)
    private Integer challengerStep = 0;

    @Column(length = 100)
    private String challengerName;

    @Column(length = 200)
    private String challengerAvatar;


    /**
     * 起始日期
     */
    @JsonSerialize(using = DateJsonSerializer.class)
    @Column(nullable = false, columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
    private Date startDate;

    /**
     * 截止日期
     */
    @JsonSerialize(using = DateJsonSerializer.class)
    @Column(nullable = false, columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
    private Date endDate;


    @ColumnDefault("0")
    @Column(nullable = false, columnDefinition="TINYINT", length = 1)
    private boolean isAwarded = false;

}
